package org.hackystat.devcathlon.ui;

import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Logger;
import org.hackystat.devcathlon.engine.match.Match;
import org.hackystat.devcathlon.engine.match.MatchManager;
import org.hackystat.utilities.logger.HackystatLogger;
import org.hackystat.utilities.tstamp.Tstamp;

/**
 * CancelTask class cancels tasks.
 * 
 * @author John Zhou
 */
public class CancelTask extends TimerTask {

  /**
   * Runs the scheduled task.
   */
  @Override
  public void run() {
    for (Match match : MatchManager.getInstance().getAllMatches()) {
      try {
        if (match.getEndTime().compare(Tstamp.makeTimestamp()) < 0) {
          for (Timer timer : match.getAllTimer()) {
            Logger logger = HackystatLogger.getLogger("org.hackystat.devcathlon", "devcathlon");
            logger.info("Removing event task");
            timer.cancel();
          }
        }
      }
      catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }

  }

}
